package com.kiln.juxingqs.ui.vm

import android.app.Application
import androidx.lifecycle.MutableLiveData
import client.global.commlib.network.data.JsonResult
import client.global.commlib.network.data.Ret
import com.kiln.juxingqs.api.bean.GetBathRet
import com.kiln.juxingqs.api.bean.GetDddRet
import com.kiln.juxingqs.ui.viewmodel.MiddleVm


class DddjyViewModel(app: Application) : MiddleVm(app) {
    val isShowing = MutableLiveData<Boolean>(false)
    val sellNum = MutableLiveData<String>("")

    val isOneLoading = MutableLiveData<Boolean>(false)
    val isTwoLoading = MutableLiveData<Boolean>(false)
    val pageOne = MutableLiveData<Int>(0)
    val pageTwo = MutableLiveData<Int>(0)
    val callOne = MutableLiveData<JsonResult<GetDddRet>>()
    val callTwo = MutableLiveData<JsonResult<GetDddRet>>()
    val buyRet = MutableLiveData<JsonResult<Ret>>()
    val sellRet = MutableLiveData<JsonResult<Ret>>()

    val currOrder = MutableLiveData<GetDddRet.Order>()

    fun holdOne() {
        if (isOneLoading.value!!)
            return
        hold({
            server.order_hall(pageOne.value!!)
        }, {
            isOneLoading.value = true
            pageOne.value = pageOne.value!! + 1
        }, {
            callOne.value = it
        }, complete = {
            isOneLoading.value = false
        })
    }

    fun holdTwo() {
        if (isTwoLoading.value!!)
            return
        hold({
            server.order_hall(pageTwo.value!!, 2)
        }, {
            isTwoLoading.value = true
            pageTwo.value = pageTwo.value!! + 1
        }, {
            callTwo.value = it
        }, complete = {
            isTwoLoading.value = false
        })
    }



    //挂卖获取批次
    fun holdBuy(currOrder: GetDddRet.Order, num: String) {
        hold({
            server.deal_buy(
                "${currOrder.order_id}",
                num,
            )
        }, {
            isShowing.value = true
        }, success = {
            buyRet.value = it
        }, complete = {
            isShowing.value = false

        })
    }

    //挂卖
    fun holdSell(b: GetBathRet.Bath) {
        hold({
            server.deal_sell(
                "${currOrder.value!!.order_id}",
                "${b.bath_id}",
                sellNum.value!!,
            )
        }, {
            isShowing.value = true
        }, success = {
            sellRet.value = it
        }, complete = {
            isShowing.value = false

        })
    }
}